package top.kuanghua.goods.config;

import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Component;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

@Component
@EnableSwagger2 //开启在线接口文档
public class Swagger2Config {

    @Value("${localservice.ipAddr}")
    private String ipAddr;
    @Value("${server.port}")
    private String port;

    /**
     * 添加摘要信息(Docket)
     */
    @Bean
    public Docket controllerApi() {
        return new Docket(DocumentationType.SWAGGER_2)
                .host(this.ipAddr + ":" + this.port)
                .apiInfo(new ApiInfoBuilder()
                        .title("标题：fai")
                        .description("描述：自定义的一个项目")
                        .contact(new Contact("jzfai", null, "869653722@qq.com"))
                        .version("版本号:0.1.0")
                        .build())
                .select()
                .apis(RequestHandlerSelectors.withMethodAnnotation(ApiOperation.class))
                .paths(PathSelectors.any())
                .build();
    }
}
